package com.yanqu.road.server.cross3server.cmd.activity.config;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.pb.cross3.server.CrossChannelServerProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityInfoMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Cross3Protocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = Cross3Protocol.C3_SYNC_REFRESH_CHANNEL_ACTIVITY_SWITCH, desc = "刷新跨域活动开关")
public class SyncRefreshChannelActivitySwitchCmd extends CrossCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossChannelServerProto.SyncRefreshChannelActivitySwitchRespMsg reqMsg = CrossChannelServerProto.SyncRefreshChannelActivitySwitchRespMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ActivityInfo activityInfo = ActivityInfoMgr.getActivityInfo(activityId);
        if (activityInfo != null) {
            for (long serverId : activityInfo.getServerIdList()) {
                CrossChannelServerProto.SyncRefreshChannelActivitySwitchRespMsg.Builder builder = CrossChannelServerProto.SyncRefreshChannelActivitySwitchRespMsg.newBuilder();
                builder.setActivityId(activityId);
                YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_SYNC_REFRESH_CHANNEL_ACTIVITY_SWITCH_FROM_CROSS3, builder);
                MessageHelper.sendPacket(serverId, 0, message);
            }
        }
    }

    @Override
    public void sendData() {

    }
}
